package com.hospital.hospitalserver.controller;

import com.hospital.hospitalserver.entity.PatientRegistrationRequest;
import com.hospital.hospitalserver.service.RegistrationService;
import com.hospital.hospitalserver.util.Response;
import com.sun.tools.jconsole.JConsoleContext;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 挂号缴费相关
 * */
@CrossOrigin
@RestController
@RequiredArgsConstructor
@RequestMapping("/registration")
public class RegistrationController {
    private final RegistrationService registrationService;

    /**
     * 提交挂号信息（未缴费）
     * */
    @PostMapping("/addRegistration")
    public Response RegistrationAdd(@RequestBody PatientRegistrationRequest request){
        try {
            return registrationService.registrationAdd(request);
        } catch (Exception e) {
            return Response.error("挂号提交失败: " + e.getMessage());
        }
    }

    /**
     * 缴费修改挂号缴费状态
     * */
    @PostMapping("/completePayment")
    public Response RegistrationCompletedPayment(@RequestBody PatientRegistrationRequest request){
        try {
            return registrationService.completePayment(request);
        } catch (Exception e) {
            e.printStackTrace(); // 添加详细错误日志
            return Response.error("缴费完成失败: " + e.getMessage());
        }
    }
}
